package com.liqi.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.liqi.common.annotation.Log;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.enums.BusinessType;
import com.liqi.info.domain.TInfoDdmp;
import com.liqi.info.service.ITInfoDdmpService;
import com.liqi.common.utils.poi.ExcelUtil;
import com.liqi.common.core.page.TableDataInfo;

/**
 * 当地名片Controller
 * 
 * @author ruoyi
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/info/ddmp")
public class TInfoDdmpController extends BaseController
{
    @Autowired
    private ITInfoDdmpService tInfoDdmpService;

    /**
     * 查询当地名片列表
     */
    @PreAuthorize("@ss.hasPermi('info:ddmp:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInfoDdmp tInfoDdmp)
    {
        startPage();
        List<TInfoDdmp> list = tInfoDdmpService.selectTInfoDdmpList(tInfoDdmp);
        return getDataTable(list);
    }

    /**
     * 导出当地名片列表
     */
    @PreAuthorize("@ss.hasPermi('info:ddmp:export')")
    @Log(title = "当地名片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInfoDdmp tInfoDdmp)
    {
        List<TInfoDdmp> list = tInfoDdmpService.selectTInfoDdmpList(tInfoDdmp);
        ExcelUtil<TInfoDdmp> util = new ExcelUtil<TInfoDdmp>(TInfoDdmp.class);
        util.exportExcel(response, list, "当地名片数据");
    }

    /**
     * 获取当地名片详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:ddmp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tInfoDdmpService.selectTInfoDdmpById(id));
    }

    /**
     * 新增当地名片
     */
    @PreAuthorize("@ss.hasPermi('info:ddmp:add')")
    @Log(title = "当地名片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInfoDdmp tInfoDdmp)
    {
            tInfoDdmp.setDeptId(getDeptId().toString());
            tInfoDdmp.setCreateUserId(getUserId().toString());
            tInfoDdmp.setStatus(0);
            tInfoDdmp.setCreateBy("admin");
        return toAjax(tInfoDdmpService.insertTInfoDdmp(tInfoDdmp));
    }

    /**
     * 修改当地名片
     */
    @PreAuthorize("@ss.hasPermi('info:ddmp:edit')")
    @Log(title = "当地名片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInfoDdmp tInfoDdmp)
    {
        return toAjax(tInfoDdmpService.updateTInfoDdmp(tInfoDdmp));
    }

    /**
     * 删除当地名片
     */
    @PreAuthorize("@ss.hasPermi('info:ddmp:remove')")
    @Log(title = "当地名片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInfoDdmpService.deleteTInfoDdmpByIds(ids));
    }
}
